class T():
    a = 1
    b = 2
    c = 3

t = T()

# res = input("请输入您要获取的属性: ")
#
# print(res)  #  --> a  t.a
# print(t.res)

# dic = {
#     "a": "mzuhou",
#     "b": 19,
# }
# res = input("请输入您要获取的属性: ")
#
# print(res)  #  --> a  t.a
# print(dic[res])

"""
反射就是通过字符串的形式去对象（模块）中操作（查找/获取/删除/添加）成员，一种基于字符串的事件驱动

反射有三个函数:

getattr, 通过字符串获取对象的属性/方法
setattr, 通过字符串给对象的属性/方法赋值
hasattr, 通过字符串来判断对象是否拥有某个属性/方法
"""


class TestObj:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def test(self):
        print("执行test方法")


def a():
    print("类外部方法")


xiaoyu = TestObj('小宇', 18)

# print(getattr(xiaoyu, "name"))  # 获取对象属性/对象方法
#
# test = getattr(xiaoyu, "test")  # 获取对象方法
# test()
# i = getattr(xiaoyu, "name") if hasattr(xiaoyu, "name") else ""
#
# print(hasattr(xiaoyu, "name"))  # 判断对象是否有对应的属性及方法,返回True或Fals
#
# setattr(xiaoyu, "name", "winnie")  # 修改属性的值
# setattr(xiaoyu, "test1", a)  # 修改方法
#
# print(xiaoyu.name)
# test1 = getattr(xiaoyu, "test1")  # 获取对象方法
# test1()
#
print(xiaoyu.name)
delattr(xiaoyu, "name")  # 删除指定的属性
print(xiaoyu.name)  # 报错
